/*
CCP 7.7
Design an algorithm to find the kth number such 
that the only prime factors are 3, 5, and 7.
*/
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

int KthPrime(int k)
{
	vector<int> ans(k);
	int i3,i5,i7,num3,num5,num7;
	i3=i5=i7=0;
	ans[0]=1;
	for(int i=1;i<k;i++)
	{
		num3 = ans[i3]*3;
		num5 = ans[i5]*5;
		num7 = ans[i7]*7;
		ans[i] = min(min(num3,num5),num7);
		if(ans[i] == num3)
			i3++;
		if(ans[i] == num5)
			i5++;
		if(ans[i] == num7)
			i7++;
	}
	return ans[k-1];
}

int main(int argc, char const *argv[])
{
	for(int i=1;i<=10;i++)
		cout<<KthPrime(i)<<endl;
	return 0;
}